package com.herench.bs.handler;


import com.herench.bs.agent.IInHosAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by liuxiaohui on 2019/3/26.
 */
@Component
@Handler(code = "200105",name="患者提交入院申请：DoAppointInHos()")
public class DoAppointInHosHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");

        // 患者ID
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        // 入院次数
        String visitId = requestMessage.getArgsPropertyStringValue("visitId");
        // 患者姓名
        String patientName = requestMessage.getArgsPropertyStringValue("patientName");
        // 性别
        String sex = requestMessage.getArgsPropertyStringValue("sex");
        // 出生日期
        String birthDate = requestMessage.getArgsPropertyStringValue("birthDate");
        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        // 邮政编码
        String zipCode = requestMessage.getArgsPropertyStringValue("zipCode");
        // 联系电话
        String phoneNumber = requestMessage.getArgsPropertyStringValue("phoneNumber");
        // 入院方式
        String patientClass = requestMessage.getArgsPropertyStringValue("patientClass");
        // 入院病情
        String patAdmCondition = requestMessage.getArgsPropertyStringValue("patAdmCondition");
        // 入院目的
        String admissionCause = requestMessage.getArgsPropertyStringValue("admissionCause");
        // 押金金额
        String prepayment = requestMessage.getArgsPropertyStringValue("prepayment");
        // 入院科室编码
        String deptAddmissionTo = requestMessage.getArgsPropertyStringValue("deptAddmissionTo");
        // 预约入院个性需求ID
        String appInHosRequireId = requestMessage.getArgsPropertyStringValue("appInHosRequireId");
        // 预约入院个性需求选项序
        String appInHosRequireOptionSeq = requestMessage.getArgsPropertyStringValue("appInHosRequireOptionSeq");
        // 门诊诊断
        String clinicDiagnosis = requestMessage.getArgsPropertyStringValue("clinicDiagnosis");
        // 门诊号
        String clinicId = requestMessage.getArgsPropertyStringValue("clinicId");



        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IInHosAgent inHosAgent = getCleverClinicContext().getApplicationContext().getBean(IInHosAgent.class);
        // 设定入参：微信
        Map<String, Object> res = inHosAgent.doAppointInHos(channelCode, hospitalCode, patientId, visitId, patientName, sex, birthDate, idNo, zipCode, phoneNumber, patientClass, patAdmCondition, admissionCause, prepayment, deptAddmissionTo, clinicDiagnosis, clinicId, appInHosRequireId, appInHosRequireOptionSeq);

        // 设置应答信息：HIS前置
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
